import axios from "axios";
import Qs from "qs";
import config from "@/config/config"

const Axios = axios.create({
  baseURL: config.baseURL,
  timeout: 10000,
  responseType: "json",
  withCredentials: false,
  headers: {
    "Content-Type": "application/x-www-form-urlencoded"
  }
});

Axios.interceptors.request.use(
  config => {
    if (config.method == "post") {
      let postData = config.data;
      let d = Qs.stringify(postData, { arrayFormat: "repeat" });
      config.data = d;
    }
    return config;
  },
  error => {
    return Promise.reject(error);
  }
);

// 返回状态判断(添加响应拦截器)
Axios.interceptors.response.use(
  res => {
    // let data = res.data
    return res;
  },
  error => {
    return Promise.reject(error);
  }
);

export default Axios;
